<template>
  <div class="hazTree">
    <div class="haz-header" v-if="!hideTitle">
      调查对象分类
    </div>
    <div>
      <el-tree class="filter-tree"
            :data="treeData"
            :props="defaultProps"
            default-expand-all highlight-current :expand-on-click-node="false"
            check-on-click-node
            @check="categoryCheckHandler"
        ref="tree">
        <template #default="{ data }">
          <el-tooltip :content="data.label" placement="top">
            <span class="tree-node-label">{{ data.label }}</span>
          </el-tooltip>
        </template>
      </el-tree>
    </div>
  </div>
</template>

<script lang="ts">
import {Component, Vue,Prop} from 'vue-property-decorator';
import {
  getHistoryWorkCategoryTree
} from '@/api/investWork';

@Component({
  components: {}
})
export default class HazTreeHistory extends Vue {
  @Prop()
  private hideTitle?:boolean;
  private treeData: any = [];
  private defaultProps: any = {
    children: 'children',
    label: 'label'
  }
  categoryCheckHandler(data: any) {
    this.$emit('selected', data);
  }

  getCategoryTree(bigCategoryId?:number){
    getHistoryWorkCategoryTree({bigCategoryId: bigCategoryId}).then(res =>{
      if(res){
          this.treeData = res.data;
      }
    });
  }

  mounted(){
    this.getCategoryTree();
    (this as any).$bus.$on('categoryCheckedHandler',(item:any) =>{

        this.getCategoryTree(item.id);
    });

  }

}
</script>
<style lang="scss" scoped>
.hazTree{
  width: 260px;
  background-color: #ffffff;
  padding: 12px 0;
  .haz-header{
    height: 28px;
    line-height: 28px;
    color: #006400;
    padding-left: 18px;
    border-left: 10px solid #006400;
    font-size: 18px;
    font-weight: bold;
    background: linear-gradient(to right, #f0f5ff , #f5f5f5);
  }
}

::v-deep .filter-tree {
.tree-node-label {
  display: inline-block;
  max-width: 200px; /* 根据实际容器宽度调整 */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 节点内容区域 */
  .el-tree-node__content {
    height: 40px;
    &:hover {
      background-color: #f5f5f5 !important;
    }
  }

  /* 节点标签 */
  .el-tree-node__label {
    color: #606266;
    font-size: 14px;
  }

  /* 当前选中节点 */
  .el-tree-node.is-current > .el-tree-node__content {
     background-color: #f0f5ff !important;
    .el-tree-node__label {
      color: #ffffff !important;
    }
  }

}
</style>
